﻿
namespace HSS.Xaml.UI.Controls
{
	#region Using Directives
	using System.Collections.Generic;
	using HSS.ComponentModel;
	#endregion

	#region BooleanValueEditor
	/// <summary>
	/// An editor for a Boolean Type
	/// </summary>
	public class BooleanValueEditor : ComboBoxEditorBase
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="descriptor">The <see cref="HSSPropertyDescriptor"/> being edited.</param>
		public BooleanValueEditor(HSSPropertyDescriptor descriptor)
			: base(descriptor)
		{
		}
		/// <summary>
		/// Gets the collection of objects for the Boolean ComboBox editor (true, false).
		/// </summary>
		/// <returns>The items for the list.</returns>
		protected override IEnumerable<object> GetListItems()
		{
			return new object[] { true, false };
		}

		/// <summary>
		/// Performs the default action.
		/// </summary>
		public override void ExecuteDefaultAction()
		{
			if (null != this.Object && !this.Descriptor.IsReadOnly)
			{
				bool value = (bool)this.Object;
				if (value)
					this.Object = false;
				else
					this.Object = true;
				this.SyncValue(this.Object);
				this.EndEdit();
			}
		}
	}
	#endregion
}
